Telegram Group & Telegram Channel
🔧 Как настроить Service Worker для офлайн-режима

Service Worker — это JS-скрипт, работающий в фоне. Он позволяет кэшировать ресурсы и обслуживать запросы без подключения к сети.

Почему важно:

🎱 Доступ к сайту без интернета

🎱 Быстрая загрузка повторно посещаемых страниц

🎱 Гибкий контроль над кэшированием

Как внедрить:

1. Регистрируем Service Worker:

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(() => console.log('SW зарегистрирован'))
.catch(err => console.error('SW ошибка:', err));
}


2. Создаем sw.js:

const CACHE_NAME = 'app-cache-v1';
const urlsToCache = ['/', '/index.html', '/styles.css'];

self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
);
});


3. Обслуживаем запросы:

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});


4. Обновляем кэш при необходимости:

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key)))
)
);
});


💡 С помощью Service Worker можно создавать PWA, ускорять загрузку и обеспечить стабильную работу в нестабильных сетях.

🐸 Библиотека фронтендера

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/frontendproglib/6244
Create:
Last Update:

🔧 Как настроить Service Worker для офлайн-режима

Service Worker — это JS-скрипт, работающий в фоне. Он позволяет кэшировать ресурсы и обслуживать запросы без подключения к сети.

Почему важно:

🎱 Доступ к сайту без интернета

🎱 Быстрая загрузка повторно посещаемых страниц

🎱 Гибкий контроль над кэшированием

Как внедрить:

1. Регистрируем Service Worker:

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(() => console.log('SW зарегистрирован'))
.catch(err => console.error('SW ошибка:', err));
}


2. Создаем sw.js:

const CACHE_NAME = 'app-cache-v1';
const urlsToCache = ['/', '/index.html', '/styles.css'];

self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
);
});


3. Обслуживаем запросы:

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});


4. Обновляем кэш при необходимости:

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key)))
)
);
});


💡 С помощью Service Worker можно создавать PWA, ускорять загрузку и обеспечить стабильную работу в нестабильных сетях.

🐸 Библиотека фронтендера

#буст

BY Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js




Share with your friend now:
tg-me.com/frontendproglib/6244

View MORE
Open in Telegram


Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js Telegram | DID YOU KNOW?

Date: |

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js from sg


Telegram Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js
FROM USA